package com.zhongxin.wymovieticket;

import java.util.ArrayList;
import java.util.List;

import com.amap.api.mapcore.util.i;
import com.amap.api.maps.AMap;
import com.amap.api.maps.MapView;
import com.amap.api.maps.model.BitmapDescriptor;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.MarkerOptions;
import com.zhoujing.Entity.Cinema;
import com.zhoujing.Entity.CinemaDetailEntity;
import com.zhoujing.Entity.CinemaEntity;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;

public class GaoDeMapActivity extends Activity {

	private MapView mapView;
	private AMap aMap;
	private CinemaDetailEntity cinemaDetailEntity;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_baidu_map);
		//得到电影院的资料
		Intent intent=getIntent();
		Bundle bundle =intent.getBundleExtra("bundle");
		cinemaDetailEntity = (CinemaDetailEntity) bundle.getSerializable("cinemaDetailEntity");
		Log.i("", "------------map"+cinemaDetailEntity.getCinemas().size()+"--"+cinemaDetailEntity.getRetcode());
		
		mapView=(MapView) this.findViewById(R.id.gaodemap);
		mapView.onCreate(savedInstanceState);//必须要写
		init();
		setPointInMap();
	}

	/**
	 * 在地图上显示电影院
	 */
	private void setPointInMap() {
		// TODO Auto-generated method stub
		
		List<Cinema> cinemaEntities=cinemaDetailEntity.getCinemas();
		for (int i = 0; i < cinemaEntities.size(); i++) {
			BitmapDescriptor bitmapDescriptor=BitmapDescriptorFactory.fromResource(R.drawable.da_marker_red);
			Cinema cinema=cinemaEntities.get(i);
			String position=cinema.getCoord();
			String ss[]=position.split(",");
			Double jingdu=Double.parseDouble(ss[0]);
			Double wudu=Double.parseDouble(ss[1]);
			LatLng latLng=new LatLng(wudu,jingdu);
			Log.i("", "------------精度"+jingdu+"------"+wudu+"-----------"+i);
			MarkerOptions markerOptions=new MarkerOptions().position(latLng).icon(bitmapDescriptor);
			Log.i("", "----------1-----------"+i);
			aMap.addMarker(markerOptions);
			Log.i("", "---------2------------"+i);
		}
		
		
		
	}

	private void init() {
		// TODO Auto-generated method stub
		if (aMap==null) {
			aMap=mapView.getMap();
		    //设置地图模式
			aMap.setMapType(AMap.MAP_TYPE_NORMAL);
		}
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		mapView.onResume();
	}
	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		mapView.onPause();
	}
	@Override
	protected void onSaveInstanceState(Bundle outState) {
		// TODO Auto-generated method stub
		super.onSaveInstanceState(outState);
		mapView.onSaveInstanceState(outState);
	}
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		mapView.onDestroy();
	}
	
}
